<?php

namespace app\common\model;

use think\Db;
use think\Model;

class BackendUserGroupModel extends Model
{
    protected $resultSetType = 'collection';
    protected $table = "basic_backend_user_group";
    protected $autoWriteTimestamp = true;
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $pageSize = 15;

    //获取所有的权限
    public function getAllUserGroup()
    {
        $where = [
            'status' => ['neq', 111]
        ];

        $userGroup = self::where($where)->select();
        $userGroup = empty($userGroup) ? [] : collection($userGroup)->toArray();
        return $userGroup;
    }

    //列表页面
    public function getUserGroupList($params = [])
    {
        $curPage = isset($params['page']) && $params['page'] > 1 ? $params['page'] : 1;
        $where = [
            'status' => ['neq', 111]
        ];

        $total = self::where($where)->count();
        $lists = self::where($where)->page("{$curPage},{$this->pageSize}")->select();

        return [
            'data' => $lists,
            'pages' => ceil($total / $this->pageSize),
            'curPage' => $curPage,
            'pageSize' => $this->pageSize,
            'totalRow' => $total,
        ];
    }

    //查询单个权限组
    public function getUserGroupById($id)
    {
        return self::find($id);
    }

    //删除
    public function deleteAll($id)
    {
        if (!is_array($id)) {
            $id = [$id];
        }

        return self::where("id", "in", $id)->update([
            'status' => 111,
            'update_time' => time()
        ]);
    }

}